package org.apache.shiro.samples;

import org.apache.shiro.realm.Realm;
import org.apache.shiro.realm.text.TextConfigurationRealm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Webster
 * <p>
 * Description:Spring Boot Application that show the usage of a user login, checking permissions, and annotation protected methods.
 * </p>
 * @date 2021/3/10
 * @see org.apache.shiro.samples
 * @see QuickStart
 * @see SimpleService
 */
@Configuration
@SpringBootApplication
public class CliApp { //NOPMD

	public static void main(String[] args) {

		ConfigurableApplicationContext context = SpringApplication.run(CliApp.class, args);

		// Grab the 'QuickStart' bean, call 'run()' to start the example.
		context.getBean(QuickStart.class).run();
	}

	/**
	 * Example hard coded Realm bean.
	 *
	 * @return hard coded Realm bean
	 */
	@Bean
	public Realm realm() {
		TextConfigurationRealm realm = new TextConfigurationRealm();
		realm.setUserDefinitions("user=123456,user\n" +
				"admin=123456,admin");

		realm.setRoleDefinitions("admin=read,write\n" +
				"user=read");
		realm.setCachingEnabled(true);
		return realm;
	}
}
